// /***** color-palette *****/
$theme_red:         #D93025;
$theme_light_red:   #FF1744;
$theme_pink:        #E91E63;
$theme_purple:      #9C27B0;
$theme_deep_purple: #673AB7;
$theme_indigo:      #3949AB;
$theme_blue:        #0091EA;
$theme_light_blue:  #0288D1;
$theme_cyan:        #5E35B1;
$theme_dark_cyan:   #4769d2;
$theme_teal:        #188c75;
$theme_green:       #4CAF50;
$theme_sea_green:   #6ab878;
$theme_lime:        #C0CA33;
$theme_yellow:      #FFD600;
$theme_dark_yellow: #F57F17;
$theme_amber:       #FFA000;
$theme_orange:      #FF6D00;
$theme_deep_orange: #F4511E;
$theme_brown:       #6D4C41;
$theme_grey:        #424242;
$theme_dark_grey:   #323232;
$theme_blue_grey:   #37474F;
$theme_green_grey:  #3b4342;
// /***** color-palette *****/

// Some color theme stuff
@mixin color_theme($check_rules:'true',
                   $switch_rules:'true',
                   $entry_rules:'true',
                   $button_rules:'true',
                   $scale_rules:'true',
                   $theme_color:$primary) {
  @if $check_rules=='true' {
    check, radio {
      &:checked, &:indeterminate {
        color: $theme_color;
      }
    }

    radio {
      & {
        border-image-source: -gtk-gradient(radial,
                                           center center, 0,
                                           center center, 0.001,
                                           to($theme_color),
                                           to(transparent));
      }

      &:checked:not(:indeterminate) {
        border-image-source: -gtk-gradient(radial,
                                           center center, 0,
                                           center center, (10px / $check_radio_size / 2),
                                           to($theme_color),
                                           to(transparent));
      }
    }
  }

  @if $switch_rules=='true' {
    switch {
      &:checked { background-color: rgba($theme_color, 0.5); }

      &:checked slider {
        background-color: $theme_color;
        color: $theme_color;
      }
    }
  }

  @if $entry_rules=='true' {
    entry, spinbutton:not(.vertical) {
      &:focus { @include entry(checked, $fc: $theme_color); }

      selection {
        color: on($theme_color);
        background-color: $theme_color;
      }
    }

    label {
      selection {
        color: on($theme_color);
        background-color: $theme_color;
      }
    }
  }

  @if $button_rules=='true' {
    button:not(.flat):not(.combo):not(.radio):not(.popup):not(.toggle):not(.titlebutton) {
      &:checked {
        color: on($theme_color);
        background-color: $theme_color;
      }

      &:checked:disabled {
        @include button(checked-disabled);
      }
    }

    button.combo {
      &:checked { @include entry(checked, $fc: $theme_color); }
    }
  }

  @if $scale_rules=='true' {
    scale {
      highlight {
        background-image: image($theme_color);
      }

      slider { color: $theme_color; }
    }
  }
}

//
// Terminal
//
terminal-window {
  > headerbar.titlebar {
    background-color: $theme_sea_green;

    &:backdrop { background-color: darken($theme_sea_green, 2%); }
  }

  notebook {
    &:focus tab:checked {
      box-shadow: inset 0 0 0 9999px rgba($theme_sea_green, 0.12);
    }

    > header {
      &.top {
        > tabs {
          > tab {
            border-image: linear-gradient(to top, transparent 2px, transparent 2px) 2 / 0 0 2px;

            &:checked { border-image-source: linear-gradient(to top, $theme_sea_green 2px, $frame 2px); }
          }
        }
      }

      tab {
        background-image: radial-gradient(circle, rgba($theme_sea_green, 0.35) 10%, transparent 0%);

        &:checked {
          background-image: radial-gradient(circle, transparent 10%, transparent 0%);
        }
      }
    }
  }

  @include color_theme($theme_color:$theme_sea_green);
}

//
// Gedit
//
window.org-gnome-gedit {
  > paned.titlebar {
    background-color: $theme_amber;

    &:backdrop { background-color: darken($theme_amber, 2%); }

    > separator {
      background-image: image($theme_amber);
      border-top: 1px solid transparent;
    }

    // > headerbar {
    //   background-color: $theme_deep_purple;
    // }
  }

  notebook {
    &:focus tab:checked {
      box-shadow: inset 0 0 0 9999px rgba($theme_amber, 0.12);
    }

    > header {
      &.top {
        > tabs {
          > tab {
            border-image: linear-gradient(to top, transparent 2px, transparent 2px) 2 / 0 0 2px;

            &:checked { border-image-source: linear-gradient(to top, $theme_amber 2px, $frame 2px); }
          }
        }
      }

      tab {
        background-image: radial-gradient(circle, rgba($theme_amber, 0.35) 10%, transparent 0%);

        &:checked {
          background-image: radial-gradient(circle, transparent 10%, transparent 0%);
        }
      }
    }
  }

  @include color_theme($theme_color:$theme_amber);
}

//
// Gnome Contacts
//
// headerbar.titlebar.contacts-left-header-bar,
// headerbar.titlebar.contacts-right-header-bar { // 3.22
//   background-color: $theme_indigo;
// }

hdyleaflet {
  > stack > frame {
    entry.search {
      &:focus { @include entry(checked, $fc: $theme_cyan); }
    }
  }
}

//
// Gnome Calender
//
window.org-gnome-Calendar {
  headerbar.titlebar {
    background-color: $theme_green;

    &:backdrop { background-color: darken($theme_green, 2%); }
  }

  @include color_theme($theme_color:$theme_green);
}

//
// Gnome Tweak Tool (Gnome Tweaks)
//

window.background.csd {
  > hdyleaflet.titlebar {
    > headerbar.titlebar.tweak-titlebar-left,
    > headerbar.titlebar.tweak-titlebar-right {
      background-color: $theme_brown;

      &:backdrop { background-color: darken($theme_brown, 2%); }

      switch {
        &:checked { background-color: rgba(lighten($theme_brown, 25%), 0.5); }

        &:checked slider {
          background-color: lighten($theme_brown, 25%);
          color: lighten($theme_brown, 25%);
        }
      }
    }

    > separator {
      background-color: $theme_brown;
    }
  }

  > hdyleaflet > box.vertical {
    > stack.main-container {
      @include color_theme($theme_color:$theme_brown);
    }

    > searchbar {
      entry.search {
        @include button(normal);

        border-radius: $corner-radius;
        box-shadow: none;
        border-image: none;
        background-color: $fill;

        &:focus {
          transition: $transition,
                      background-size 0ms,
                      background-image 0ms;
          animation: ripple $ripple-fade-in-duration $ease-out forwards;
          box-shadow: inset 0 0 0 9999px $overlay-hover, $shadow-z8;
          background-image: radial-gradient(circle, $overlay-checked 10%, transparent 0%);
          background-size: 0% 0%;

          box-shadow: none;
          border-image: none;
        }

        selection {
          color: on($theme_brown);
          background-color: $theme_brown;
        }

        &:backdrop {
          animation: none;
          transition: none;
        }
      }
    }
  }
}

// the sidebar
.tweak-categories {
  row.activatable.tweak-category {
    &:selected {
      color: if($variant == 'light', $theme_brown, lighten($theme_brown, 35%));

      image, label { color: if($variant == 'light', $theme_brown, lighten($theme_brown, 35%)); }
    }
  }
}

//
// Gnome Control Center
//
window.background.csd {
  > headerbar.titlebar > hdyleaflet {
    > headerbar {
      background-color: $theme_cyan;
      box-shadow: inset 0 1px highlight($titlebar), inset 0 -1px $divider;

      &:backdrop { background-color: darken($theme_cyan, 2%); }

      &:first-child:not(:only-child) {
        border-top-left-radius: $window-radius;
      }

      &:last-child:not(:only-child) {
        border-top-right-radius: $window-radius;
      }

      &:first-child:only-child, &:last-child:only-child {
        border-top-right-radius: $window-radius;
        border-top-left-radius: $window-radius;
      }

      switch {
        &:checked { background-color: rgba(lighten($theme_cyan, 25%), 0.5); }

        &:checked slider {
          background-color: lighten($theme_cyan, 25%);
          color: lighten($theme_cyan, 25%);
        }
      }
    }

    > separator {
      background-color: $theme_cyan;
      box-shadow: inset 0 1px highlight($titlebar);
    }
  }

  > hdyleaflet > stack.background {
    @include color_theme($theme_color:$theme_cyan);

    scale {
      slider {
        color: $theme_cyan;

        @each $s, $as in ('', '') {
          &#{$s} {
            $_url: 'assets/scale-slider#{$as}#{$asset-suffix}-cyan';

            background-image: -gtk-scaled(url('#{$_url}.png'), url('#{$_url}@2.png')),
                              radial-gradient(circle, transparent 10%, transparent 0%);
          }
        }

        &:active {
          $_url: 'assets/scale-slider#{$asset-suffix}-cyan';
          background-image: -gtk-scaled(url('#{$_url}.png'), url('#{$_url}@2.png')),
                            radial-gradient(circle, $overlay-active 10%, transparent 0%);
          background-size: auto, 0% 0%;
        }
      }
    }
  }

  > hdyleaflet > box.vertical {
    > scrolledwindow.view {
      > viewport.frame {
        > stack {
          entry.search {
            &:focus { @include entry(checked, $fc: $theme_cyan); }

            selection {
              color: on($theme_cyan);
              background-color: $theme_cyan;
            }
          }
        }

        > stack, > stack > box.vertical {
          > list > row.activatable {
            &:selected {
              color: if($variant == 'light', $theme_cyan, lighten($theme_cyan, 35%));

              image, label { color: if($variant == 'light', $theme_cyan, lighten($theme_cyan, 35%)); }
            }
          }
        }
      }
    }
  }
}

//
// Gnome Builder
//
window.background.csd.org-gnome-Builder {
  > stack.titlebar {
    background-color: $theme_grey;

    &:backdrop { background-color: darken($theme_grey, 2%); }

    > headerbar {
      > box.horizontal > stack.suggestionbutton {
        > button { @extend %button-flat; }
      }
    }
  }

  @include color_theme($theme_color:$theme_grey);
}

//
// Gnome-system-monitor
//
window#gnome-system-monitor {
  headerbar.titlebar {
    background-color: $theme_teal;

    &:backdrop { background-color: darken($theme_teal, 2%); }
  }

  @include color_theme($theme_color:$theme_teal);

  treeview.view {
    &.progressbar { // progress bar in treeviews
      border-bottom: $bar-size solid $theme_teal;
    }
  }
}

//
// Gnome-Todo
//
window.org-gnome-Todo {
  headerbar.titlebar {
    background-color: $theme_deep_orange;

    &:backdrop { background-color: darken($theme_deep_orange, 2%); }
  }

  @include color_theme($theme_color:$theme_deep_orange);
}

//
// Dconf-editor
//
window.dconf-editor {
  headerbar.titlebar {
    background-color: $theme_purple;

    &:backdrop { background-color: darken($theme_purple, 2%); }
  }

  @include color_theme($theme_color:$theme_purple);
}

//
// Gnome-Logs
//
headerbar.titlebar.event_toolbar {
  background-color: $theme_dark_yellow;

  &:backdrop { background-color: darken($theme_dark_yellow, 2%); }
}

//
// Geary
//
window#GearyMainWindow {
  > .titlebar {
    background-color: $theme_red;

    &:backdrop { background-color: darken($theme_red, 2%); }

    > headerbar {
      box-shadow: none;
    }
  }

  @include color_theme($theme_color:$theme_red);
}

//
// Budgie Setting Window
//
window.background.csd.budgie-settings-window {
  > headerbar.titlebar {
    background-color: $theme_blue_grey;

    &:backdrop { background-color: darken($theme_blue_grey, 2%); }
  }

  @include color_theme($theme_color:$theme_blue_grey);
}

//Dialogs

dialog.background.csd {
  > headerbar.titlebar {
    background-color: $theme_pink;

    &:backdrop { background-color: darken($theme_pink, 2%); }
  }

  @include color_theme($theme_color:$theme_pink);

  .linked.path-bar > button {
    @extend %button-flat;

    border-image: radial-gradient(circle closest-corner at center calc(100% - 1px),
                                  $theme_pink 0%,
                                  transparent 0%)
                                  0 0 0 / 0 0 0px;

    &:checked {
      color: on($background);
      border-image: radial-gradient(circle closest-corner at center calc(100% - 1px),
                                    $theme_pink 100%,
                                    transparent 0%)
                                    0 0 2 / 0 0 2px;

      &, &:disabled { background-color: transparent; }
    }
  }

  // the sidebar
  .sidebar row.activatable {
    &:selected {
      color: $theme_pink;

      image, label { color: $theme_pink; }
    }
  }

  notebook {
    &:focus tab:checked {
      box-shadow: inset 0 0 0 9999px rgba($theme_pink, 0.12);
    }

    > header {
      &.top {
        > tabs {
          > tab {
            border-image: linear-gradient(to top, transparent 2px, transparent 2px) 2 / 0 0 2px;

            &:checked { border-image-source: linear-gradient(to top, $theme_pink 2px, $frame 2px); }
          }
        }
      }

      tab {
        background-image: radial-gradient(circle, rgba($theme_pink, 0.35) 10%, transparent 0%);

        &:checked {
          background-image: radial-gradient(circle, transparent 10%, transparent 0%);
        }
      }
    }
  }
}
